import java.util.*;
import java.text.DateFormat;


public class Customer {
	private String ccode;
	private String name;
	private String surname;
	private Date born;
	private Address addr;
	private Document doc;
	private String email;
	private String phone;
	private String fcode;
	
	public Customer () {}
	
	public Customer (String name, String surname, String born, Address addr, String email, String phone, String fcode) throws Exception {
		this.setName(name);
		this.setSurname(surname);
		this.setBorn(born);
		this.setAddr(addr);
		this.setEmail(email);
		this.setPhone(phone);
		this.setFcode(fcode);
	}
	
	public Customer (Customer cust) {
		this.name = cust.getName();
		this.surname = cust.getSurname();
		this.born = cust.getBorn();
		this.addr = cust.getAddress();
		this.email = cust.getEmail();
		this.phone = cust.getPhone();
		this.fcode = cust.getFcode();
	}
	
	public void setName(String name) {
		if (name.matches("^[a-zA-Z]+$")) {
			this.name = name;
		}
		else {
			// Formato nome non corretto
			System.out.println("err");
		}
	}
	
	public void setSurname(String surname) {
		if (surname.matches("^[a-zA-Z]+$")) {
			this.surname = surname;
		}
		else {
			// Formato cognome non corretto
			System.out.println("err");
		}
	}
	
	public void setBorn(String data) throws Exception {
		DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, Locale.ITALY);
		this.born = df.parse(data);
	}
	
	public void setAddr(String city, String cap, String way, int num) {
		this.addr = new Address(city, cap, way, num);
	}
	
	public void setAddr(Address addr) {
		this.addr = new Address(addr);
	}
	
	public void setDoc(String doc) {
		
	}
	
	public void setEmail(String email) {
		if (email.matches("^[0-9a-zA-Z_.]+@[a-zA-Z]+\\.[a-zA-Z]{2,3}$")) {
			this.email = email;
		}
		else {
			// Formato email non corretto
			System.out.println("err");
		}
	}
	
	public void setPhone(String phone) {
		if (phone.matches("^[0-9]+$")) {
			this.phone = phone;
		}
		else {
			// Formato telefono non corretto
			System.out.println("err");
		}
	}
	
	public void setFcode(String fcode) {
		if (fcode.matches("^[A-Za-z]{6}[0-9]{2}[A-Za-z]{1}[0-9]{2}[A-Za-z]{1}[0-9]{3}[A-Za-z]{1}$")) {
			this.fcode = fcode;
		}
		else {
			// Formato codice fiscale non corretto
			System.out.println("err");
		}
	}
	
	public String getName() {
		return this.name;
	}
	
	public String getSurname() {
		return this.surname;
	}
	
	public Date getBorn() {
		return (Date)this.born.clone();
	}
	
	public Address getAddress() {
		return (Address)this.addr.clone();
	}
	
	public String getEmail() {
		return this.email;
	}
	
	public String getPhone() {
		return this.phone;
	}
	
	public String getFcode() {
		return this.fcode;
	}
	
	public String toString() {
		return "Nome: " + this.name + 
		"\nCognome: " + this.surname +
		"\nData di nascita: " + this.born +
		"\nIndirizzo: " + this.addr +
		"\nEmail: " + this.email +
		"\nphone: " + this.phone +
		"\nCodice Fiscale: " + this.fcode;
	}
	
	protected Object clone() {
		return new Customer(this);
	}
	
	public boolean equals(Object o) {
		Customer temp = (Customer) o;
		if (temp == this) return true;
		if (temp == null) return false;
		return temp.getName().equals(this.name) 
		&& temp.getSurname().equals(this.surname)
		&& temp.getBorn().equals(this.born)
		&& temp.getEmail().equals(this.email)
		&& temp.getPhone().equals(this.phone)
		&& temp.getAddress().equals(this.addr)
		&& temp.getFcode().equals(this.fcode);
	}
	
	
}
